package com.hunter.robot;

import lombok.extern.slf4j.Slf4j;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.Random;

/**
 * @Project:iwms
 * @Description: 键盘模拟
 * @Author: Mr.Hunter
 * @Date:2022/5/21/12:48
 */
@Slf4j
public class KeyBoarRobot {

    private Robot robot = null;

    public KeyBoarRobot() {
        try {
            robot = new Robot();
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
    public  void  Zh(String Zhz)  {
        String zh[] = Zhz.split("");
        Sr(zh);
    }
    public  void Sr(String srz[] ) {

        Random random = new Random();
        robot.delay(5000);
        for (int i = 0;i < srz.length;i++){
            String sr = srz[i];
            double t1 = 0.2 + random.nextDouble() * (0.4-0.2);
            t1 = t1 * 100;
            switch (sr) {
                case "a":
                    robot.keyPress(KeyEvent.VK_A);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_A);
                    robot.delay((int) t1);
                    break;
                case "b":
                    robot.keyPress(KeyEvent.VK_B);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_B);
                    robot.delay((int) t1);
                    break;
                case "c":
                    robot.keyPress(KeyEvent.VK_C);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_C);
                    robot.delay((int) t1);
                    break;
                case "d":
                    robot.keyPress(KeyEvent.VK_D);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_D);
                    robot.delay((int) t1);
                    break;
                case "e":
                    robot.keyPress(KeyEvent.VK_E);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_E);
                    robot.delay((int) t1);
                    break;
                case "f":
                    robot.keyPress(KeyEvent.VK_F);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_F);
                    robot.delay((int) t1);
                    break;
                case "g":
                    robot.keyPress(KeyEvent.VK_G);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_G);
                    robot.delay((int) t1);
                    break;
                case "h":
                    robot.keyPress(KeyEvent.VK_H);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_H);
                    robot.delay((int) t1);
                    break;
                case "i":
                    robot.keyPress(KeyEvent.VK_I);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_I);
                    robot.delay((int) t1);
                    break;
                case "j":
                    robot.keyPress(KeyEvent.VK_J);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_J);
                    robot.delay((int) t1);
                    break;
                case "k":
                    robot.keyPress(KeyEvent.VK_K);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_K);
                    robot.delay((int) t1);
                    break;
                case "l":
                    robot.keyPress(KeyEvent.VK_L);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_L);
                    robot.delay((int) t1);
                    break;
                case "m":
                    robot.keyPress(KeyEvent.VK_M);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_M);
                    robot.delay((int) t1);
                    break;
                case "n":
                    robot.keyPress(KeyEvent.VK_N);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_N);
                    robot.delay((int) t1);
                    break;
                case "o":
                    robot.keyPress(KeyEvent.VK_O);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_O);
                    robot.delay((int) t1);
                    break;
                case "p":
                    robot.keyPress(KeyEvent.VK_P);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_P);
                    robot.delay((int) t1);
                    break;
                case "q":
                    robot.keyPress(KeyEvent.VK_Q);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_Q);
                    robot.delay((int) t1);
                    break;
                case "r":
                    robot.keyPress(KeyEvent.VK_R);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_R);
                    robot.delay((int) t1);
                    break;
                case "s":
                    robot.keyPress(KeyEvent.VK_S);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_S);
                    robot.delay((int) t1);
                    break;
                case "t":
                    robot.keyPress(KeyEvent.VK_T);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_T);
                    robot.delay((int) t1);
                    break;
                case "u":
                    robot.keyPress(KeyEvent.VK_U);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_U);
                    robot.delay((int) t1);
                    break;
                case "v":
                    robot.keyPress(KeyEvent.VK_V);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_V);
                    robot.delay((int) t1);
                    break;
                case "w":
                    robot.keyPress(KeyEvent.VK_W);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_W);
                    robot.delay((int) t1);
                    break;
                case "x":
                    robot.keyPress(KeyEvent.VK_X);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_X);
                    robot.delay((int) t1);
                    break;
                case "y":
                    robot.keyPress(KeyEvent.VK_Y);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_Y);
                    robot.delay((int) t1);
                    break;
                case "z":
                    robot.keyPress(KeyEvent.VK_Z);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_Z);
                    robot.delay((int) t1);
                    break;
            }
            switch (sr) {
                case "A":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_A);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_A);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "B":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_B);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_B);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "C":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_C);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_C);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "D":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_D);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_D);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "E":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_E);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_E);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "F":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_F);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_F);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "G":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_G);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_G);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "H":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_H);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_H);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "I":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_I);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_I);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "J":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_J);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_J);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "K":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_K);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_K);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "L":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_L);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_L);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "M":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_M);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_M);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "N":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_N);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_N);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "O":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_O);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_O);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "P":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_P);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_P);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "Q":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_Q);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_Q);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "R":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_R);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_R);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "S":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_S);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_S);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "T":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_T);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_T);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "U":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_U);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_U);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "V":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_V);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_V);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "W":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_W);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_W);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "X":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_X);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_X);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "Y":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_Y);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_Y);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
                case "Z":
                    robot.keyPress(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    robot.keyPress(KeyEvent.VK_Z);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_Z);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_SHIFT);
                    robot.delay((int) t1);
                    break;
            }

            switch (sr) {
                case "1":
                    robot.keyPress(KeyEvent.VK_1);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_1);
                    robot.delay((int) t1);
                    break;
                case "2":
                    robot.keyPress(KeyEvent.VK_2);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_2);
                    robot.delay((int) t1);
                    break;
                case "3":
                    robot.keyPress(KeyEvent.VK_3);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_3);
                    robot.delay((int) t1);
                    break;
                case "4":
                    robot.keyPress(KeyEvent.VK_4);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_4);
                    robot.delay((int) t1);
                    break;
                case "5":
                    robot.keyPress(KeyEvent.VK_5);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_5);
                    robot.delay((int) t1);
                    break;
                case "6":
                    robot.keyPress(KeyEvent.VK_6);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_6);
                    robot.delay((int) t1);
                    break;
                case "7":
                    robot.keyPress(KeyEvent.VK_7);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_7);
                    robot.delay((int) t1);
                    break;
                case "8":
                    robot.keyPress(KeyEvent.VK_8);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_8);
                    robot.delay((int) t1);
                    break;
                case "9":
                    robot.keyPress(KeyEvent.VK_9);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_9);
                    robot.delay((int) t1);
                    break;
                case "0":
                    robot.keyPress(KeyEvent.VK_0);
                    robot.delay((int) t1);
                    robot.keyRelease(KeyEvent.VK_0);
                    robot.delay((int) t1);
                    break;
            }
        }
    }
}